import { IProdComm } from '@/types'
import { Effect, Reducer } from 'umi';
import { getProdComm } from '@/services'

export interface ProdCommModelState {
  ProdComm: IProdComm;
}

export interface ProdCommModelType {
  namespace: 'prodProdComm';
  state: ProdCommModelState;
  effects: {
    getProdComm:Effect;
  };
  reducers: {
    save: Reducer<ProdCommModelState>;
  };
}

const ProdCommModel: ProdCommModelType = {
  namespace: 'prodProdComm',
  state: {
    ProdComm: {
      pages:0,
      records:[],
      searchCount:true,
      size:0,
      total:0,
    },
  },

  effects: {
    *getProdComm({payload}, {call, put}){
      let result = yield call(getProdComm,payload);
      if (result){
        yield put({
          type: 'save',
          payload: {
            ProdComm: result
          }
        })
      }
    },
  },
  reducers: {
    save(state, action) {
      return {
        ...state,
        ...action.payload,
      };
    },
  },
};

export default ProdCommModel;
